package postpic.app;

import org.json.JSONObject;

import postpic.app.io.ClientIO;
import postpic.domain.action.Action;
import postpic.domain.session.Request;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;

public class UploadActivity extends Activity implements OnClickListener {

	private Bitmap photo;
	private JSONObject imageObject = new JSONObject();

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.upload);
	    photo = (Bitmap) this.getIntent().getParcelableExtra("BitmapImage");
	    ImageView image = (ImageView) findViewById(R.id.pictureDisplay);
        image.setImageBitmap(photo);
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()) {
		case R.id.uploadButton:
			String caption   = ((EditText)findViewById(R.id.photoCaption)).getText().toString();
			JSONObject photoJson = new JSONObject();
			photoJson.put("userId", ClientIO.USER.getUserId());
			photoJson.put("caption", caption);
	        ClientIO.sendRequest(new Request(Action.UPLOAD_PIC, photoJson));
	        photo.compress(Bitmap.CompressFormat.PNG, 100, ClientIO.getOutputStream());
	        imageObject = new JSONObject();

			
		case R.id.uploadCancelButton:
			Intent myIntent = new Intent(v.getContext(), PostPicActivity.class);
		    v.getContext().startActivity(myIntent);
			break;
		}
	}

}
